<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>VueComponent</title>
    <script src="../js/vue.js"></script>
  </head>
  <body>
    <div id="root">
      <school></school>
      <hello></hello>
    </div>
  </body>
  <script>
    // 定义 school 组件
    const school = Vue.extend({
      template: `
      <div>
        <h2>学校名称{{name}}</h2>
          <h2>学校地址{{address}}</h2>
          <button @click="showName">点我提示学校名</button>
        </div>
      `,
      data() {
        return {
          name: "尚硅谷",
          address: "北京",
        };
      },
      methods: {
        showName() {
          alert(this.name);
          console.log(this);
          // this 为 VueComponent的实例
        },
      },
    });

    const test = Vue.extend({
      template:`<span>测试</span>`,
    })

    // 定义一个hello组件
    const hello = Vue.extend({
      template: `<div>
        <h2>{{msg}}</h2>
        <test></test>
        </div>`,
      data() {
        return {
          msg: "你好啊",
        };
      },
      components:{
        test
      }
    });

    console.log(school); // 组件本质为VueComponent构造函数
    /* ƒ VueComponent(options) {
        this._init(options);
      } */
    // 每个组件都是一个全新的 VueComponent
    console.log(school === hello); // false

    // 创建vm
    const vm = new Vue({
      el: "#root",
      components: {
        school,
        hello,
      },
    });
  </script>
</html>
